#ifndef H_SPRITE
#define H_SPRITE

#include "debug.h"
#include "rect.h"
#include <string>

#define P_LOAD_FUNCTION( varName ) int (*varName)( std::string&, void**)

class Sprite {
   private:
      std::string filename;
      void* surface;
      Rect* geometry;
      P_LOAD_FUNCTION(loadFP);
   public:
      bool animated;

      Sprite () {
	 animated = false;
      }
      Sprite ( std::string &, P_LOAD_FUNCTION(_loadFP), UINT, UINT );

int load  (  )  {
   pDebug( this << " int load ("   << ")")
 	 return loadFP(filename, &surface);
	 //Loads the file into memory
      }

std::string getFileName  (  ) const  {
   pDebug( this << " std::string getFileName ("   << ")") 
 	 return filename; }

void* getSurface (  ) const  {
   pDebug( this << " void* getSurface("   << ")") 
 	 return surface;
      }

void setSurface  ( void* _a  )  {
   pDebug( this << " void setSurface (" << "void* _a =" << &_a   << ")")
 	 surface = _a; 
      }

Rect* getGeometry (  ) const  {
   pDebug( this << " Rect* getGeometry("   << ")") 
 	 return geometry;
      }

      void setGeometry( Rect* _geo ) {
	 geometry = _geo;
      }

virtual Rect* getFrame  ( UINT i  )  {
   pDebug( this << " virtual Rect* getFrame (" << "UINT i =" << &i   << ")")
 	 return NULL; 
      }
};

class AnimatedSprite: public Sprite {
   private:
      UINT frames;
   public:
      AnimatedSprite ( std::string _filename, P_LOAD_FUNCTION(_loadFP) ,UINT _frames, UINT _width, UINT _height ) : Sprite ( _filename, _loadFP, _width, _height ) {
	 frames = _frames;

	 Rect* r = new Rect [ frames ];
	 setGeometry ( r );	 
	 generateRects( _width, _height);
	 animated = true;
      }

virtual Rect* getFrame  ( UINT i  ) const  {
   pDebug( this << " virtual Rect* getFrame (" << "UINT i =" << &i   << ")") 
 	 return getGeometry()+i; 
      }

      void generateRects( UINT, UINT);
      
UINT getFrames (  ) const  {
   pDebug( this << " UINT getFrames("   << ")") 
 	 return frames;
      }
};



#endif
